package com.ruoyi.caigou.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.caigou.domain.dto.BuySupDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caigou.domain.BuySupplies;
import com.ruoyi.caigou.service.IBuySuppliesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 供应商报价Controller
 * 
 * @author lvql
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/gysbj")
public class BuySuppliesController extends BaseController
{
    @Autowired
    private IBuySuppliesService buySuppliesService;

    /**
     * 查询供应商报价列表
     */
    @RequiresPermissions("caigou:gysbj:list")
    @GetMapping("/list")
    public TableDataInfo list(BuySupplies buySupplies)
    {
        startPage();
        List<BuySupplies> list = buySuppliesService.selectBuySuppliesList(buySupplies);
        return getDataTable(list);
    }

    /**
     * 导出供应商报价列表
     */
    @RequiresPermissions("caigou:gysbj:export")
    @Log(title = "供应商报价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuySupplies buySupplies)
    {
        List<BuySupplies> list = buySuppliesService.selectBuySuppliesList(buySupplies);
        ExcelUtil<BuySupplies> util = new ExcelUtil<BuySupplies>(BuySupplies.class);
        util.exportExcel(response, list, "供应商报价数据");
    }

    /**
     * 获取供应商报价详细信息
     */
    @RequiresPermissions("caigou:gysbj:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(buySuppliesService.selectBuySuppliesById(id));
    }
    @RequiresPermissions("caigou:gysbj:query")
    @GetMapping(value = "/info/{id}")
    public AjaxResult getInfoPlus(@PathVariable("id") Integer id)
    {
        return success(buySuppliesService.selectBuySuppliesById(id));
    }

    /**
     * 新增供应商报价
     */
    @RequiresPermissions("caigou:gysbj:add")
    @Log(title = "供应商报价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuySupplies buySupplies)
    {
        return toAjax(buySuppliesService.insertBuySupplies(buySupplies));
    }

    @PostMapping("/add")
    public AjaxResult addPlus(@RequestBody BuySupDTO buySupDTO){
        logger.info("BuySuppliesController addPlus params1 {}",buySupDTO.getBuySupplies().toString());
        logger.info("BuySuppliesController addPlus params2 {}",buySupDTO.getBuySuppliesPrices().toString());
        return toAjax(buySuppliesService.insertBuySuppliesPlus(buySupDTO));
    }

    /**
     * 修改供应商报价
     */
    @RequiresPermissions("caigou:gysbj:edit")
    @Log(title = "供应商报价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuySupplies buySupplies)
    {
        return toAjax(buySuppliesService.updateBuySupplies(buySupplies));
    }
    @PutMapping("/upd")
    public AjaxResult editPlus(@RequestBody BuySupDTO buySupDTO)
    {
        return toAjax(buySuppliesService.updateBuySuppliesPlus(buySupDTO));
    }

    /**
     * 删除供应商报价
     */
    @RequiresPermissions("caigou:gysbj:remove")
    @Log(title = "供应商报价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(buySuppliesService.deleteBuySuppliesByIds(ids));
    }
    @DeleteMapping("/del/{ids}")
    public AjaxResult removePlus(@PathVariable Integer[] ids)
    {
        return toAjax(buySuppliesService.deleteBuySuppliesByIdsPlus(ids));
    }
}
